// Arup Guha
// 1/21/2026
// Solution to 2026 COP 3330 Program #2B: Tennis Simulation

import java.util.*;

public class tennissim {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		Random rndObj = new Random();
		
		boolean over = false;
		boolean win = false;
		boolean myAd = false, yourAd = false;
		
		// me is the user, you is the computer.
		int me = 0, you = 0;
		
		// Keep going until the end of the game.
		while (!over) {
			
			// Deuce case
			if (me == 40 && you == 40 && !myAd && !yourAd)
				System.out.println("The score is Deuce.");
			
			// My Advantage
			else if (me == 40 && you == 40 && myAd)
				System.out.println("The score is Ad In.");
				
			// Your Advantage
			else if (me >= 3 && you >= 3 && yourAd)
				System.out.println("The score is Ad Out.");
				
			// Regular score.
			else 
				System.out.println("The score is "+me+"-"+you+".");
			
			// Get the play.
			System.out.println("What play would you like to make(1-10)?");
			int play = stdin.nextInt();
			
			// Basic error detection.
			while (play < 1 || play > 10) {
				System.out.println("Sorry, that is not in between 1 and 10.");
				System.out.println("Please enter a number in between 1 and 10 for your play.");
				play = stdin.nextInt();
			}
			
			// Computer's play.
			int comp = rndObj.nextInt(10) + 1;
			System.out.println("The computer played "+comp+".");
			
			if (Math.abs(play - comp) <= 2) {
				System.out.println("The computer won the point.");
				
				// Easy cases.
				if (you == 0) 
					you = 15;
				else if (you == 15)
					you = 30;
				else if (you == 30)
					you = 40;
					
				// Only ways I win.
				else if ((you == 40 && me < 40) || yourAd) {
					over = true;
					win = false;
				}
				
				// Back to deuce.
				else if (myAd)
					myAd = false;
					
				// If we get here it's the computer's ad.
				else
					yourAd = true;
			}
			
			// I (user) won the point.
			else {
			
				// Print out greeting.
				System.out.println("Congrats, you won the point!");
				
				// Easy cases.
				if (me == 0) 
					me = 15;
				else if (me == 15)
					me = 30;
				else if (me == 30)
					me = 40;
					
				// Only ways I win.
				else if ((me == 40 && you < 40) || myAd) {
					over = true;
					win = true;
				}
				
				// Back to deuce.
				else if (yourAd)
					yourAd = false;
					
				// If we get here it's the user's ad.
				else
					myAd = true;
			}
		} // end while
		
		// Print end result.
		if (win)
			System.out.println("Congrats, you win the game!");
		else
			System.out.println("Sorry, you have lost the game to the computer!");
	}
}